<?php 
$mthu=array("Su","Mo","Tu","We","Th","Fr","Sa");
$t=$_REQUEST["months"];
$n=$_REQUEST["years"];
$tenthang=$t." - ".$n;
$ntt=date("t,",mktime(0,0,0,$t,1,$n));
$vt=date("w",mktime(0,0,0,$t,1,$n));
$ngay=1;
include 'emclass.php';
include 'holidayclass.php';
$connection = mysql_connect("1.234.53.52", "cam", "5678" ) ;
mysql_select_db("testbk130108", $connection);
mysql_query("set names 'utf8'");
$s="SELECT employee.FullName,date(employee.Birthday) as Birthday,employee.IDEmployee,employee.Email from employee where employee.State=1 ORDER BY Birthday ASC";
$q=mysql_query($s);
$mbirthday=array();
$mholiday=array();
if(mysql_num_rows($q)>0){
	while($r=mysql_fetch_array($q)){
		$ob= new emclass();
		$ob->newemclass($r['IDEmployee'], $r['FullName'], $r['Email'], $r['Birthday']);
		if(isset($mbirthday[$ob->dm]) && $mbirthday[$ob->dm]!=''){
			$mbirthday[$ob->dm] .="<br> - ".$r['FullName']." (".($n - $ob->y)."t)";
		}else{
			$mbirthday[$ob->dm]=" - ".$r['FullName']." (".($n - $ob->y)."t)";
		}
	}
}
$s1="SELECT * from holiday where year(holiday.vtime)='".$n."' and month(holiday.vtime)='".$t."'";
$q1=mysql_query($s1);
if(mysql_num_rows($q1)>0){
	while($r1=mysql_fetch_array($q1)){
		$ho=new holiday();
		$ho->newholiday($r1['id'], $r1['vtime'], $r1['vcontent']);
		$mholiday[$r1['vtime']]=$ho;
	}
}
mysql_close($connection);
?>
<table align='center'  border='1' bgcolor='#eeffff' style='font-size:12px;border-collapse: collapse;'>
			<?php	
				for ($i=0;$i<7;$i++)
					{
						?>
						<tr align='center' >
						<?php 
						for ($j=0;$j<count($mthu);$j++)
							{
								if ($i==0){
								?>
									<td style='width:50px;font-size: 14px;height:50px'><font color='green'><b><?=$mthu[$j]?></b></font></td>
								<?php 
								}else
									{
										if ($i==1)
										{
											if (($j==$vt) and  ($ngay<=$ntt))
											{
												if ($j==0){
													?>
													<td style="width:120px;height:120px">
														<?php 
															$tt=$t;
															if($t<10){
																$tt="0".$t;
															}
															$nngay=$ngay;
															if($ngay<10){
																$nngay="0".$ngay;
															}
															
															$thoigian=$n."-".$tt."-".$nngay;
															$le=new holiday();
															if(isset($mholiday[$thoigian])){
																$le=unserialize (serialize ($mholiday[$thoigian]));
															}
														?>
														<table >
															<tr>
																<td  id="<?php echo 'vitri'.$ngay;?>">
																	<lable class="iclose" onclick="ajax_showTooltip(window.event,'addle.php?thoigian=<?=$thoigian?>&vitri=<?=$ngay?>&le=<?=$le->vcontent?>&style=1',this);return false" style="cursor:pointer;color:red;font-weight:bold;"><?=$ngay?></lable>
																	<br>
																	<?=$le->vcontent?>
																</td>
															</tr>
															<tr>
																<td>
																	<?php 
																		if(isset($mbirthday[$tt."-".$nngay])){
																			?>
																			<a href="#" onmouseover="ajax_showTooltip(window.event,'showbirth.php?a=<?=$mbirthday[$tt."-".$nngay]?>',this);return false" onmouseout="ajax_hideTooltip()"><img src="images/bb1.gif" style="width:80px;height:80px;"/></a>
																			<?php 
																		}
																	?>
																</td>
															</tr>
														</table>
													</td>
													<?php 
												}else{
													?>
													<td  style="width:120px;height:120px">
														<?php 
															$tt=$t;
															if($t<10){
																$tt="0".$t;
															}
															$nngay=$ngay;
															if($ngay<10){
																$nngay="0".$ngay;
															}
															
															$thoigian=$n."-".$tt."-".$nngay;
															$le=new holiday();
															if(isset($mholiday[$thoigian])){
																$le=unserialize (serialize ($mholiday[$thoigian]));
															}
														?>
														<table >
															<tr>
																<td id="<?php echo 'vitri'.$ngay;?>">
																	<lable class="iclose" onclick="ajax_showTooltip(window.event,'addle.php?thoigian=<?=$thoigian?>&vitri=<?=$ngay?>&le=<?=$le->vcontent?>&style=2',this);return false" style="cursor:pointer"><?=$ngay?></lable>
																	<br>
																	<?=$le->vcontent?>
																</td>
															</tr>
															<tr>
																<td >
																	<?php 
																		if(isset($mbirthday[$tt."-".$nngay])){
																			?>
																			<a href="#" onmouseover="ajax_showTooltip(window.event,'showbirth.php?a=<?=$mbirthday[$tt."-".$nngay]?>',this);return false" onmouseout="ajax_hideTooltip()"><img src="images/bb1.gif" style="width:80px;height:80px;" /></a>
																			<?php 
																		}
																	?>
																</td>
															</tr>
														</table>
													</td>
													<?php 
												}
												$vt++;
												$ngay++;
											}
											else{
												?>
												<td style="width:120px;height:120px" ></td>
												<?php 
											}								
										}
										else
										{
											$vt=0;
											if ($ngay<=$ntt)
											{
												if ($j==0){
													?>
													<td style="width:120px;height:120px" >
														<?php 
															$tt=$t;
															if($t<10){
																$tt="0".$t;
															}
															$nngay=$ngay;
															if($ngay<10){
																$nngay="0".$ngay;
															}
															
															$thoigian=$n."-".$tt."-".$nngay;
															$le=new holiday();
															if(isset($mholiday[$thoigian])){
																$le=unserialize (serialize ($mholiday[$thoigian]));
															}
														?>
														<table>
															<tr>
																<td id="<?php echo 'vitri'.$ngay;?>">
																	<lable class="iclose" onclick="ajax_showTooltip(window.event,'addle.php?thoigian=<?=$thoigian?>&vitri=<?=$ngay?>&le=<?=$le->vcontent?>&style=1',this);return false" style="cursor:pointer;color:red;font-weight:bold;"><?=$ngay?></lable>
																	<br>
																	<?=$le->vcontent?>
																</td>
															</tr>
															<tr>
																<td >
																	<?php 
																		if(isset($mbirthday[$tt."-".$nngay])){
																			?>
																			<a href="#" onmouseover="ajax_showTooltip(window.event,'showbirth.php?a=<?=$mbirthday[$tt."-".$nngay]?>',this);return false" onmouseout="ajax_hideTooltip()"><img src="images/bb1.gif" style="width:80px;height:80px;" /></a>
																			<?php 
																		}
																	?>
																</td>
															</tr>
														</table>
													</td>
													<?php 
												}else{
													?>
													<td style="width:120px;height:120px" >
														<?php 
															$tt=$t;
															if($t<10){
																$tt="0".$t;
															}
															$nngay=$ngay;
															if($ngay<10){
																$nngay="0".$ngay;
															}
															
															$thoigian=$n."-".$tt."-".$nngay;
															$le=new holiday();
															if(isset($mholiday[$thoigian])){
																$le=unserialize (serialize ($mholiday[$thoigian]));
															}
														?>
														<table >
															<tr>
																<td id="<?php echo 'vitri'.$ngay;?>">
																	<lable class="iclose" onclick="ajax_showTooltip(window.event,'addle.php?thoigian=<?=$thoigian?>&vitri=<?=$ngay?>&le=<?=$le->vcontent?>&style=2',this);return false" style="cursor:pointer"><?=$ngay?></lable>
																	<br>
																	<?=$le->vcontent?>
																</td>
															</tr>
															<tr>
																<td >
																	<?php 
																		if(isset($mbirthday[$tt."-".$nngay])){
																			?>
																			<a href="#" onmouseover="ajax_showTooltip(window.event,'showbirth.php?a=<?=$mbirthday[$tt."-".$nngay]?>',this);return false" onmouseout="ajax_hideTooltip()"><img src="images/bb1.gif"  style="width:80px;height:80px;"/></a>
																			<?php  
																		}
																	?>
																</td>
															</tr>
														</table>
													</td>
													<?php 
												}
												$ngay++;
												$vt++;		
											}
											else{
												?>
												<td style="width:120px;height:120px" ></td>
												<?php 
											}
										}						
									}	
							}	
							?>			
						</tr>
						<?php 
							
					} 
		?>
				</table>